﻿using Dm.Domain.Repository.EntityRepositories;
using Dm.Domain.CrossCutting;

namespace Dm.Domain.Business.Specifications
{
    public class KeyAutoGeneratorBusiness
    {
        private KeyAutoGeneratorRepository _keyAutoGenerator;
        public KeyAutoGeneratorBusiness(BaseContext context)
        {
            this._keyAutoGenerator = new KeyAutoGeneratorRepository();
        }

        public string CurrentStudentNumber
        {
            get
            {
                var studentSetting = _keyAutoGenerator.Retrieve(BusinessSettings.StudentSetting.KeyAutoGeneratorId);

                studentSetting.Indexer += 1;

                string studentNumber = string.Format("{0}{1}{2}", studentSetting.Prefix, studentSetting.Indexer, studentSetting.Suffix);
                  
                _keyAutoGenerator.Update(studentSetting);

                return studentNumber;
            }
        }
    }
}
